package com.cy.核心编程.thead.theadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * cached线程池.无限创建线程池
 * Thread.currentThread()控制某个线程
 */
public class TestCache {
    private static AtomicInteger i = new AtomicInteger();

    public static void main(String[] args) {
        ExecutorService es = Executors.newCachedThreadPool();
        for (int j = 0; j < 100; j++) {
            int key = TestCache.i.getAndIncrement();
            System.out.println("创建子线程:" + key);
            es.execute(() -> {
                for (int i = 0; i < 100; i++) {
                    System.out.println("子线程:" +Thread.currentThread().getName()+"  key:"+ key + "===>>>>" + i);
                }
            });
        }

        for (int i = 0; i < 100; i++) {
            System.out.println("主线程" + i);
        }
    }
}
